<?php require_once('../Connections/locale.php'); ?>
<?php
mysql_select_db($database_locale, $locale);
$query_categorie = "SELECT * FROM categorie";
$categorie = mysql_query($query_categorie, $locale) or die(mysql_error());
$row_categorie = mysql_fetch_assoc($categorie);
$totalRows_categorie = mysql_num_rows($categorie);

mysql_select_db($database_locale, $locale);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="stylesheet" type="text/css" href="../style.css">
<title>Untitled Document</title>
</head>

<body>
<fieldset>
<legend>Elenco Categorie</legend>
<table border="1" id="datatable">
  <tr>
    <td><div align="center"><strong>ID Categoria </strong></div></td>
    <td><div align="center"><strong>Descrizione Categoria</strong></div></td>
	    <td><div align="center"><strong>Numeri Extra</strong></div></td>
    <td><div align="center"><strong><a href="inserimento_categoria.php"><img src="../images/page.gif" width="18" height="18" border="0" /></a></strong></div></td>
    <td><div align="center"></div></td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_categorie['id_categoria']; ?></td>
      <td><?php echo $row_categorie['descrizione_categoria']; ?></td>
	  <td><?php echo $row_categorie['numeri_extra']; ?></td>
      <td><a href="modifica_categoria.php?id_categoria=<?php echo $row_categorie['id_categoria']; ?>"><img src="../images/modifica.png" width="16" height="16" border="0" /></a></td>
      <td><a href="elimina_categoria.php?id_categoria=<?php echo $row_categorie['id_categoria']; ?>">
        <?php 
		$query_legami_abbonati = "SELECT * FROM abbonati WHERE id_categoria =".$row_categorie['id_categoria'];
$legami_abbonati = mysql_query($query_legami_abbonati, $locale) or die(mysql_error());
$row_legami_abbonati = mysql_fetch_assoc($legami_abbonati);
$totalRows_legami_abbonati = mysql_num_rows($legami_abbonati);
		if ($totalRows_legami_abbonati == 0) { // Show if recordset empty ?>
          <img src="../images/elimina.png" width="16" height="16" border="0" />
      <?php } // Show if recordset empty ?></a></td>
    </tr>
    
    <?php } while ($row_categorie = mysql_fetch_assoc($categorie)); ?>
</table>
</fieldset>
</body>
</html>
<?php
mysql_free_result($categorie);

mysql_free_result($legami_abbonati);
?>
